package com.example.function.integration.service.impl;

import com.example.function.integration.service.AbstractCommonDataService;
import com.example.function.integration.service.InitTestDataToDBService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description: 初始化测试数据到数据库服务接口实现类
 * @ClassName: ImportAndExportServiceImpl
 * @Author: ext.fengcheng
 * @Create: 2023-08-08 15:41
 */
@Service
public class InitDataDataToDBServiceImpl extends AbstractCommonDataService implements InitTestDataToDBService {

    @Override
    @Transactional
    public boolean initDBData(String tenantId, String tableName) {
        if (TB_CREDIT_APPLY_RECORD.equals(tableName)) {
            initCreditDataToDB();
        }
        return true;
    }

    public boolean initCreditDataToDB() {
        for (int i = 0; i < INIT_NUM; i++) {
            int finalI = i;
            executor.submit(() -> {
                crlCreditApplyRecordExtendMapper.insert(bulidCrlCreditApplyRecordObj(finalI));
                crlCreditApproveRecordExtendMapper.insert(bulidCrlCreditApproveRecordObj(finalI, null));
            });
        }
        return true;
    }

    public T bulidCrlCreditApplyRecordObj(int index) {
        T applyRecord = new T();
        // 数据库对象，初始化值
        /*
        applyRecord.setCreditApplyNo("CreditApplyNo20230914" + index);
        applyRecord.setCreditApplyType(CreditApplyTypeEnum.CASH_LOAN_CUSTOMER_ACTIVE_APPLY);
        applyRecord.setProductCode("huaneng_jintiao");
        applyRecord.setProductVersion(0);
        applyRecord.setChannelCode(ChannelCodeEnum.JT);
        applyRecord.setCustomerCode("CustomerCode20230914" + index);
        applyRecord.setUserId("UserId20230914" + index);
        applyRecord.setOutsideCreditNo("OutsideCreditNo20230914" + index);
        applyRecord.setOutsideReqTime(new Date());
        applyRecord.setChannelCustomerCode("ChannelCustomerCode20230914" + index);
        applyRecord.setCreditApplyStatus(CreditApplyStatusEnum.INIT);
        applyRecord.setReqTime(new Date());
        applyRecord.setFinishedTime(new Date());
        applyRecord.setBizDate(new Date());
        applyRecord.setTag1("");
        applyRecord.setTag2("");
        applyRecord.setUserName("UserName20230914" + index);
        applyRecord.setCertNo("CertNo20230914" + index);
        applyRecord.setApplyMsg("测试");
        applyRecord.setCreditBatchNo("CreditBatchNo20230914" + index);
        applyRecord.setOutChannelCode("OutChannelCode20230914" + index);
        applyRecord.setBdcChannelCode("BdcChannelCode20230914" + index);
        applyRecord.setCompanyId("482");
        applyRecord.setTenantId("morse_dev_demo");
        */
        return applyRecord;
    }

    public T bulidCrlCreditApproveRecordObj(int index, String creditApplyNo) {
        T applyRecord = new T();
        // 数据库对象，初始化值
        /*
        applyRecord.setCreditApproveNo("CreditApproveNo20230914" + index);
        applyRecord.setCreditApplyNo(creditApplyNo);
        applyRecord.setProductCode("huaneng_jintiao");
        applyRecord.setChannelCode(ChannelCodeEnum.JT);
        applyRecord.setCustomerCode("CustomerCode20230914" + index);
        applyRecord.setUserId("UserId20230914" + index);
        applyRecord.setCreditApproveStatus(CreditApproveStatusEnum.INIT);
        applyRecord.setApproveOrgan("");
        applyRecord.setApproveOutsideNo("ApproveOutsideNo20230914" + index);
        applyRecord.setApproveReqTime(new Date());
        applyRecord.setApproveRetNo("ApproveRetNo20230914" + index);
        applyRecord.setApproveRetCode("ApproveRetCode20230914" + index);
        applyRecord.setApproveRetMsg("测试");
        applyRecord.setApproveRetTime(new Date());
        applyRecord.setBizDate(new Date());
        applyRecord.setApproveReqContent(APPROVE_REQ_CONTENT);
        applyRecord.setApproveRetContent(APPROVE_RET_CONTENT);
        applyRecord.setCompanyId("482");
        applyRecord.setTenantId("morse_dev_demo");
        */
        return applyRecord;
    }

}
